package com.yhb.channel.utils;

import com.yhb.channel.model.ChannelLocation;
import com.yhb.channel.provider.IGeographicLocationProvider;
import lombok.var;
import org.apache.http.util.TextUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

@Service
public class ChannelLocationService {
    @Autowired
    private IGeographicLocationProvider locationProvider;

    private final ChannelLocation mockLocation = ChannelLocation.builder()
            .province("广东省")
            .city("深圳市")
            .area("南山区")
            .build();

    public ChannelLocation getMockLocation() {
        return mockLocation;
    }

    public static final List<String> municipalitys = Arrays.asList(
            "北京市",
            "重庆市",
            "天津市",
            "上海市"
    );

    public ChannelLocation getLocation() {
        var location = locationProvider.getLocation();
        var city = location.getCity();
        if (TextUtils.isEmpty(city)) {
            city = location.getArea();
        }
        return ChannelLocation.builder()
                .province(location.getProvince())
                .city(city)
                .area(location.getArea())
                .build();
    }

}
